import { reportForms } from "@/api/index";
import { table } from "@/api";
import { mapState, mapActions } from "vuex";
import { columnsScreen, derives } from "./columns";
import RmsDetail from "@components/table/dialog/RmsDetail"
export default {
  name: "rmsDetails",
  data () {
    return {
      total: 0,
      pageSizeOptions: [10, 20, 50, 100, 500],
      pageNo: 1,
      pageSize: 10,
      combineTr: 7,
      dialogVisible: false,
      loading: false,
      particularYear: '',
      pickDate: '',
      markValue: '',
      params: {
        page: 1,
        size: 10,
      },
      derive: {},
      shipData: {},
      tableData: [],
      columns: [],
      fromTime: [],
      markOptions: [
        {
          label: '全部',
          value: ''
        },
        {
          label: '未匹配上合约运单',
          value: 1
        },
        {
          label: '送货时效顺延',
          value: 2
        },
        {
          label: '回单时效顺延',
          value: 3
        }
      ],
      userInfo: sessionStorage.getItem('userInfo')
    };
  },
  computed: {
    ...mapState({
      // tenantId: (state) => state.login.tenantId,
      menuId: (state) => state.menu.menu.menuId
    }),
    user () {
      return JSON.parse(this.userInfo)
    },
    tenantId () {
      return this.user?.tenantId
    }
  },
  mounted () {
    this.columns = columnsScreen(36188);
    this.derive = derives(36188);
    setTimeout(() => {
      this.locationInHone();
    }, 1500);
  },
  methods: {
    // 是否带参
    locationInHone () {
      this.params.uuId = this.$route.query.uuId
      this.search(2);
    },
    markChange (e) {
      switch (e) {
        case 1:
          this.params.matchContractFlag = false;
          this.params.deliveryTimeFlag = false;
          this.params.receiptTimeFlag = false;
          break
        case 2:
          this.params.matchContractFlag = false;
          this.params.deliveryTimeFlag = true;
          this.params.receiptTimeFlag = false;
          break
        case 3:
          this.params.matchContractFlag = false;
          this.params.deliveryTimeFlag = false;
          this.params.receiptTimeFlag = true;
          break
        case '':
          delete this.params.matchContractFlag
          delete this.params.deliveryTimeFlag
          delete this.params.receiptTimeFlag
          break
      }
      this.search(1)
    },
    //返回
    handelClose () {
      window.close();
    },
    // 切换页数大小
    handleSizeChange () {
      this.search(2);
    },
    // 分页
    handleCurrentChange () {
      this.search(2);
    },
    // 查询
    async search (type) {
      this.params.page = type == 1 ? 1 : this.pageNo,
        this.pageNo = type == 1 ? 1 : this.pageNo,
        this.params.size = this.pageSize
      this.tableData = []
      this.loading = true
      let { data } = await reportForms.rmsList(this.params, 36188)
      let datas = data.data
      let code = data.code
      if (code === 0) {
        this.loading = false
        this.tableData = datas.records;
      } else {
        this.loading = false
        this.tableData = []
      }
      this.total = datas.total;
    },
    // 导出
    async handleExport () {
      if (!this.tableData.length) {
        this.$message.warning("没有可要导出的数据！");
        return false;
      }
      let args = JSON.parse(JSON.stringify(this.params))
      args.page = 1
      args.size = this.total
      let params = {
        args: { ...args },
        name: this.derive.name,
        type: this.derive.type
      };
      await table.submitFormContainer(`/export/task`, params);
      this.searchCount();
      this.$nextTick(() => {
        this.$message.success("导出功能正在后台执行中，请稍后去“导出文件”下载中查看！");
      });
    },
    // 查询导出未读数
    ...mapActions({
      searchCount: "login/exportCount"
    }),
    dialog (data) {
      this.dialogVisible = true;
      this.shipData = data;
    },
    handleClose () {
      this.dialogVisible = false;
    },
    digitalConversion (data) {
      let value
      if (data == 100) {
        value = data + '%'
      } else if (data == 0 || !data) {
        value = '0%'
      } else {
        value = data.toFixed(2) + '%'
      }
      return value
    },
    sortableProp (name) {
      let sortable
      if (name == '异常单号') {
        sortable = 'custom'
      } else if (name == '异常数') {
        sortable = 'custom'
      } else if (name == '异常运单数') {
        sortable = 'custom'
      } else if (name == '异常箱数') {
        sortable = 'custom'
      } else {
        sortable = false
      }
      return sortable
    },
    transition (val, text) {
      let value
      if (text == 'number') {
        value = val ? val : '0'
      } else if (text == 'string') {
        value = val ? val : '--'
      } else if (text == 'time') {
        value = val ? val.substr(0, 10) : '--'
      } else {
        value = val
      }
      return value
    }
  },
  components: {
    RmsDetail
  }
};